#!/bin/bash

# JPY汇率检测系统卸载脚本

set -e

echo "🗑️  开始卸载JPY汇率检测系统..."

# 停止并禁用服务
echo "⏹️  停止服务..."
sudo systemctl stop jpy-rate.service 2>/dev/null || true
sudo systemctl stop jpy-rate.timer 2>/dev/null || true
sudo systemctl disable jpy-rate.service 2>/dev/null || true
sudo systemctl disable jpy-rate.timer 2>/dev/null || true

# 删除systemd文件
echo "🗑️  删除systemd文件..."
sudo rm -f /etc/systemd/system/jpy-rate.service
sudo rm -f /etc/systemd/system/jpy-rate.timer
sudo systemctl daemon-reload

# 删除项目目录
PROJECT_DIR="/home/pi/jpy2-cny"
if [ -d "$PROJECT_DIR" ]; then
    echo "🗑️  删除项目目录: $PROJECT_DIR"
    sudo rm -rf "$PROJECT_DIR"
fi

echo "✅ 卸载完成！"
echo ""
echo "📋 已删除的内容:"
echo "  - 项目目录: $PROJECT_DIR"
echo "  - systemd服务文件"
echo "  - 数据库文件"
echo "  - 日志文件"
echo ""
echo "⚠️  注意: 如果修改了防火墙规则，请手动恢复"
